home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 February / WN_129_CD.iso / Windows / Extensions Firefox / FlashGot / flashgot-0.5.3.xpi / chrome / flashgot.jar / content / flashgot / flashgot.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2004-11-14  |  2.3 KB  |  104 lines

  1. #!/bin/sh
  2. DMS_NAMES[0]="Aria"
  3. DMS_CMDS[0]='aria'
  4. DMS_NAMES[1]="Downloader 4 X"
  5. DMS_CMDS[1]='nt'
  6.  
  7. DMS_COUNT=${#DMS_CMDS[*]}
  8.  
  9. check() {
  10.   echo -n "${DMS_NAMES[$j]}|"
  11.   path=$(which "${DMS_CMDS[$j]}" 2>/dev/null) && echo "OK" || echo "BAD"
  12. }
  13.  
  14. checkAll() {
  15.  j=$DMS_COUNT; while (( j-- > 0 )); do
  16.         check ${DMS_CMDS[$j]} "${DMS_NAMES[$j]}"
  17.  done
  18. }
  19.  
  20. launch_nt() {
  21.   nt "$1" &
  22. }
  23.  
  24. launch_aria() {
  25.   aria -r "$referrer" $optSaveDir -g "$1" &
  26. }
  27.  
  28. launch() {
  29.   j=$DMS_COUNT; while (( j-- >0 )); do
  30.         if [ "${DMS_NAMES[$j]}" == "$dmsName" ] ; then
  31.           dmsCmd="${DMS_CMDS[$j]}"
  32.           DMS_ID=$j
  33.           j=0
  34.         fi
  35.   done
  36.   optSaveDir=""
  37.   case "$dmsCmd" in
  38.     "nt" | "aria" )
  39.       if [ "$saveDir" ]; then
  40.         if [ "$dmsCmd" == "nt" ]; then
  41.           nt -d "$saveDir" &
  42.           sleep 1
  43.         else
  44.           optSaveDir=${saveDir:+-d"$saveDir"}
  45.         fi
  46.       fi
  47.       j=0; while (( j<linksCount )); do
  48.         "launch_$dmsCmd" "${urls[$j]}" "${info[$j]}" "${cookies[$j]}" "${postData[$j]}"
  49.         echo "launched $dmsCmd" "url: ${urls[$j]}" "info: ${info[$j]}" "cookie: ${cookies[$j]}" "postData: ${postData[$j]}"
  50.       (( j++ )); done
  51.       if [ "$dmsCmd" == "aria" -a $linksCount -gt 0 ]; then
  52.         sleep 3
  53.         aria -s &
  54.       fi
  55.       ;;
  56.      *) echo >2 "Unknown Download Manager $dmsName"
  57.         ;;
  58.    esac
  59. }
  60.  
  61. if [ "$1" == "-o" ]; then
  62.   echo "$(checkAll)" > "$2"
  63. else
  64.  
  65.   ph() {
  66.     ph="${line%%;*}" 
  67.     line="${line#*;}"
  68.   }
  69.   
  70.   parseFile() { 
  71.     export linesIdx=0 linksIdx=0 linksCount=0 
  72.     while read line; do
  73.       case $linesIdx in
  74.         0) ph && linksCount=$ph
  75.            ph && dmsName=$ph
  76.            ph && optType=$ph
  77.            ph && saveDir=$ph
  78.            ;;
  79.         1) referrer="$line" ;;
  80.         *) echo "linesIdx $linesIdx linksIdx $linksIdx linksCount $linksCount"
  81.            if [ $linksIdx -lt $linksCount ]; then
  82.             case $(( linesIdx % 4 )) in
  83.               2) urls[$linksIdx]="$line" ;;
  84.               3) info[$linksIdx]="$line" ;;
  85.               0) cookies[$linskIdx]="$line" ;;
  86.               1) postData[$linksIdx]="$line"
  87.                  linksIdx=$(( linksIdx+1 )) 
  88.                  ;;
  89.             esac
  90.            fi
  91.            ;;
  92.        esac
  93.       linesIdx=$(( linesIdx+1 ))
  94.     done
  95.     echo "linesIdx $linesIdx linksIdx $linksIdx linksCount $linksCount"
  96.     launch
  97.   }
  98.   
  99.   cat "$1" | parseFile
  100.   
  101. fi
  102.  
  103.  
  104.